package com.demo.easyExcel;

import com.alibaba.excel.EasyExcel;
import com.demo.easyExcel.listen.PeopleListener;
import com.demo.easyExcel.pojo.People;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class test {
    public List<People> getData() {
        List<People> peoples = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            People people = new People(i + "", "无语", "十八");
            peoples.add(people);
        }
        return peoples;
    }

    @Test
    public void test1() {
        String file = "C:\\Users\\Administrator\\Desktop\\test1.xls";
        EasyExcel.write(file, People.class).sheet("班级").doWrite(getData());
    }

    public String getPath() {
        String path = this.getClass().getResource("/").getPath();
        return path;
    }

    @Test
    public void test02() {
        System.out.println(getPath());
    }

    @Test
    public void test03() {
        String file = getPath() + "student_01.xls";
        EasyExcel.write(file, People.class).sheet("班级").doWrite(getData());
    }

    //    读取excel的内容
    @Test
    public void test4() {
        String file = "C:\\Users\\Administrator\\Desktop\\test1.xls";
//        这个sheet指的是  对应文件的名字，一个excel有多个sheet。
        EasyExcel.read(file, People.class, new PeopleListener()).sheet("班级").doRead();
    }
}
